﻿using System.Runtime.InteropServices;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using QQChat.ViewModels;
using QQChat.Views;

namespace QQChat;

public partial class App : Application
{
    public override void Initialize()
    {
        AvaloniaXamlLoader.Load(this);
    }

    public override void OnFrameworkInitializationCompleted()
    {
        if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
        {
            desktop.MainWindow = new MainWindow
            {
                DataContext = new MainViewModel()
            };

            AddWindowClasses(desktop.MainWindow.Classes);
        }
        else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform)
        {
            singleViewPlatform.MainView = new MainView
            {
                DataContext = new MainViewModel()
            };
            
            AddWindowClasses(singleViewPlatform.MainView.Classes);
        }

        base.OnFrameworkInitializationCompleted();
    }

    private void AddWindowClasses(Classes classes)
    {
        if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
        {
            //classes.Clear();
            // classes.Add("Windows");
        }
        else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
        {
            classes.Clear();
            classes.Add("Mac");
        }
    }
}